<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------

namespace app\common\controller;

class Fornt extends Base {
    
    public function __construct()
    {
        // 初始化模板引擎
        $request = request();
        config('template.view_path',ROOT_PATH . '/themes/' . config('fornt_theme').  '/');
        parent::__construct();
    }

	public function _initialize() {
		parent::_initialize();

		//判读是否为关闭网站
		if (\think\Config::get('web_site_close')) {
			header("Content-type:text/html;charset=utf-8");
			echo $this->fetch('common@default/public/close');exit();
		}

		//设置SEO
		$this->setSeo();

		$this->setHoverNav();
	}

	//当前栏目导航
	protected function setHoverNav() {
		//dump($_SERVER['PHP_SELF']);
	}

    /**
     * 重写fetch，重定向模板
     * @access protected
     * @param string    $template 模板文件名
     * @param array     $vars     模板输出变量
     * @param array     $replace     模板替换
     * @param array     $config     模板参数
     * @return mixed
     */
    protected function fetch($template = '', $vars = [], $replace = [], $config = [])
    {
    	if($template==''){
    		$template=$this->parseTemplate($template);
    	}
    	$re=['__STATIC__'=>'/themes/' . config('fornt_theme') . '/static',
    		 '__IMG__'=>'/themes/' . config('fornt_theme') . '/static/images',
    		 '__CSS__'=>'/themes/' . config('fornt_theme') . '/static/css',
    		 '__JS__'=>'/themes/' . config('fornt_theme') . '/static/js',];
    	$replace=array_merge($replace,$re);
        return $this->view->fetch($template, $vars, $replace, $config);
    }
}
